home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
varia
/
gc-nov90.lha
/
gc-26nov90
/
gctest3.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-11-01
|
2KB
|
88 lines
/* The following program tests the ability of the garbage collector to correct
derived pointers and pointers in the non-garbage collected heap.
*/
/* Externals */
#include <stdio.h>
#include "gcalloc.h"
/* Cell type to build a list with. */
struct cell {
cell *next;
int* value1;
int value2;
cell( );
GCCLASS( cell );
};
void cell::GCPointers( ) {
gcpointer( next );
gcpointer( value1 );
}
cell::cell( )
{
GCALLOC( cell );
next = 0;
value1 = 0;
}
typedef cell* cellptr;
/* Dynamic array of cellptr's that is not garbage collected */
struct cella {
int count;
cellptr ptr[ 1 ];
cella( int n );
};
cella::cella( int n )
{
this = (cella*)new char*[ (n+1)*4 ];
count = n;
}
gcheap dummy( 1048576, 2147483647, 1048576, 35, 30,
GCHEAPROOTS+GCMEM+GCSTATS );
main()
{
cella* pointers = new cella( 50000 );
cellptr cl = 0, cp;
/* Allocate 50000 cells referenced by an array in the non-gc heap */
for (int i = 0; i < 50000; i++) {
cp = new cell;
pointers->ptr[ i ] = cp;
cp->value1 = 0;
cp->value2 = i;
}
/* Make a list of 50000 cells that each point into themseleves. */
for (i = 0; i < 50000; i++) {
cp = new cell;
cp = new cell;
cp = new cell;
cp = new cell;
cp->next = cl;
cp->value1 = &cp->value2;
cp->value2 = i;
cl = cp;
}
/* Verify that objects referenced by pointers still exist */
for (i = 0; i < 50000; i++) {
if (pointers->ptr[ i ]->value2 != i) abort();
}
/* Verify that cell list is correct correct */
for (i = 0; i < 50000; i++) {
if (cl->value2 != *(cl->value1)) abort();
cl = cl->next;
}
exit( 0 );
}